using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaceCat
{
    public class FCChartEx : FCChart, FCEventCallBack, FCMenuItemTouchEventCallBack
    {
        public ArrayList<String> m_floatStrs = new ArrayList<String>();

        public ArrayList<double> m_dates = new ArrayList<double>();


        public override void drawChartCrossLine(FCPaint paint, FCRect clipRect)
        {
            if (m_datas == null || m_datas.size() == 0)
            {
                return;
            }
            FCSize size = getSize();
            int candleDivHeight = getCandleDivHeight();
            int volDivHeight = getVolDivHeight();
            int indDivHeight = getIndDivHeight();
            int crossLineIndex = m_crossStopIndex;
            if (crossLineIndex == -1 || !m_showCrossLine)
            {
                if (m_lastValidIndex != -1)
                {
                    crossLineIndex = m_lastValidIndex;
                }
                else
                {
                    crossLineIndex = m_lastVisibleIndex;
                }
            }
            if (crossLineIndex < 0 || crossLineIndex > m_datas.size() - 1)
            {
                return;
            }
            if (volDivHeight > 0)
            {
                ArrayList<String> drawTitles = new ArrayList<string>();
                ArrayList<long> drawColors = new ArrayList<long>();
                drawTitles.add("VOL ".ToString() +
                    FCTran.getValueByDigit(m_datas[crossLineIndex].m_volume / m_magnitude, m_volDigit));
                drawColors.add(getTextColor());
                int iLeft = m_leftVScaleWidth + 5;
                for (int i = 0; i < drawTitles.size(); i++)
                {
                    FCSize tSize = paint.textSize(drawTitles[i], getFont(), -1);
                    paint.drawText(
                            drawTitles[i], drawColors[i], getFont(), new FCRect(iLeft, candleDivHeight + 5, iLeft + tSize.cx, candleDivHeight + 5 + tSize.cy), -1);
                    iLeft += tSize.cx + 5;
                }
            }
            //上面显示数据  高开低收
            if (m_cycle == "trend")
            {
                ArrayList<String> drawTitles = new ArrayList<string>();
                ArrayList<long> drawColors = new ArrayList<long>();
                if (m_text.Length > 0)
                {
                    drawTitles.add(m_text);
                    drawColors.add(getTextColor());
                }
                drawColors.add(getTextColor());
                int iLeft = m_leftVScaleWidth + 5;
                for (int i = 0; i < drawTitles.size(); i++)
                {
                    FCSize tSize = paint.textSize(drawTitles[i], getFont(), -1);
                    paint.drawText(drawTitles[i], drawColors[i], getFont(), new FCRect(iLeft, 5, iLeft + tSize.cx, 5 + tSize.cy), -1);
                    iLeft += tSize.cx + 5;
                }
            }
            else
            {
                ArrayList<String> drawTitles = new ArrayList<string>();
                ArrayList<long> drawColors = new ArrayList<long>();
                if (m_text.Length > 0)
                {
                    drawTitles.add(m_text);
                    drawColors.add(getTextColor());
                }
                if (m_mainIndicator == "MA")
                {
                    if (m_ma5.size() > 0)
                    {
                        drawTitles.add("MA5 ".ToString() +
                            FCTran.getValueByDigit(m_ma5[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA5");
                    }
                    drawColors.add(m_indicatorColors[0]);
                    if (m_ma10.size() > 0)
                    {
                        drawTitles.add("MA10 ".ToString() +
                            FCTran.getValueByDigit(m_ma10[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA10");
                    }
                    drawColors.add(m_indicatorColors[1]);
                    if (m_ma20.size() > 0)
                    {
                        drawTitles.add("MA20 ".ToString() +
                            FCTran.getValueByDigit(m_ma20[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA20");
                    }
                    drawColors.add(m_indicatorColors[2]);
                    if (m_ma30.size() > 0)
                    {
                        drawTitles.add("MA30 ".ToString() +
                            FCTran.getValueByDigit(m_ma30[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA30");
                    }
                    drawColors.add(m_indicatorColors[5]);
                    if (m_ma120.size() > 0)
                    {
                        drawTitles.add("MA120 ".ToString() +
                            FCTran.getValueByDigit(m_ma120[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA120");
                    }
                    drawColors.add(m_indicatorColors[4]);
                    if (m_ma250.size() > 0)
                    {
                        drawTitles.add("MA250 ".ToString() +
                            FCTran.getValueByDigit(m_ma250[crossLineIndex], m_candleDigit));
                    }
                    else
                    {
                        drawTitles.add("MA250");
                    }
                    drawColors.add(m_indicatorColors[3]);
                }
                int iLeft = m_leftVScaleWidth + 5;
                for (int i = 0; i < drawTitles.size(); i++)
                {
                    FCSize tSize = paint.textSize(drawTitles[i], getFont(), -1);
                    paint.drawText(drawTitles[i], drawColors[i], getFont(), new FCRect(iLeft, 5, iLeft + tSize.cx, 5 + tSize.cy), -1);
                    if (i == 0 && m_text.Length > 0)
                    {
                        int midY = 13;
                        FCSize cSize = paint.textSize(m_subComboBox.getText(), m_subComboBox.getFont(), -1);
                        int sWidth = cSize.cx + 25;
                        FCRect subBounds = new FCRect(iLeft + tSize.cx + 8, midY - 10, iLeft + tSize.cx + 8 + sWidth, midY + 10);
                        m_subComboBox.setBounds(subBounds);
                        iLeft += sWidth + 16;
                    }
                    iLeft += tSize.cx + 5;
                }
            }
            if (indDivHeight > 0)
            {
                ArrayList<String> drawTitles = new ArrayList<string>();
                ArrayList<long> drawColors = new ArrayList<long>();
                if (m_showIndicator == "MACD")
                {
                    if (m_alldifarr.size() > 0)
                    {
                        drawTitles.add("DIF ".ToString() +
                            FCTran.getValueByDigit(m_alldifarr[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("DIF");
                    }
                    drawColors.add(m_indicatorColors[0]);
                    if (m_alldeaarr.size() > 0)
                    {
                        drawTitles.add("DEA ".ToString() +
                            FCTran.getValueByDigit(m_alldeaarr[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("DEA");
                    }
                    drawColors.add(m_indicatorColors[1]);
                    if (m_allmacdarr.size() > 0)
                    {
                        drawTitles.add("MACD ".ToString() +
                            FCTran.getValueByDigit(m_allmacdarr[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("MACD");
                    }
                    drawColors.add(m_indicatorColors[4]);
                }
                else if (m_showIndicator == "KDJ")
                {
                    if (m_kdjK.size() > 0)
                    {
                        drawTitles.add("K ".ToString() +
                            FCTran.getValueByDigit(m_kdjK[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("K");
                    }
                    drawColors.add(m_indicatorColors[0]);
                    if (m_kdjD.size() > 0)
                    {
                        drawTitles.add("D ".ToString() +
                            FCTran.getValueByDigit(m_kdjD[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("D");
                    }
                    drawColors.add(m_indicatorColors[1]);
                    if (m_kdjJ.size() > 0)
                    {
                        drawTitles.add("J ".ToString() +
                            FCTran.getValueByDigit(m_kdjJ[crossLineIndex], m_indDigit));
                    }
                    else
                    {
                        drawTitles.add("J");
                    }
                    drawColors.add(m_indicatorColors[2]);
                }
                int iLeft = m_leftVScaleWidth + 5;
                for (int i = 0; i < drawTitles.size(); i++)
                {
                    FCSize tSize = paint.textSize(drawTitles[i], getFont(), -1);
                    paint.drawText(drawTitles[i], drawColors[i], getFont(), new FCRect(iLeft,
                            candleDivHeight + volDivHeight + 5, iLeft + tSize.cx,
                            candleDivHeight + volDivHeight + 5 + tSize.cy), -1);
                    iLeft += tSize.cx + 5;
                }
            }
            if (this == m_native.m_touchMoveView || this == m_native.m_touchDownView)
            {
                String rightText = "";
                if (m_touchPosition.y < candleDivHeight)
                {
                    rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition)
                        , m_candleDigit);
                }
                else if (m_touchPosition.y > candleDivHeight &&
                    m_touchPosition.y < candleDivHeight + volDivHeight)
                {
                    rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition) / m_magnitude
                        , m_volDigit);
                }
                else if (m_touchPosition.y > candleDivHeight + volDivHeight &&
                  m_touchPosition.y < candleDivHeight + volDivHeight + indDivHeight)
                {
                    rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition)
                        , m_indDigit);
                }

                int drawY = m_touchPosition.y;
                if (drawY > size.cy)
                {
                    drawY = size.cy;
                }
                FCSize tSize2 = paint.textSize(rightText, getFont(), -1);
                if (m_leftVScaleWidth > 0)
                {
                    paint.fillRect(m_crossTipColor, m_leftVScaleWidth - tSize2.cx, drawY - tSize2.cy / 2 - 4,
                        m_leftVScaleWidth, drawY + tSize2.cy / 2 + 3);
                    paint.drawText(rightText, getTextColor(), getFont(),
                        new FCRect(m_leftVScaleWidth - tSize2.cx, drawY - tSize2.cy / 2, m_leftVScaleWidth, drawY + tSize2.cy / 2), -1);
                }
                if (m_rightVScaleWidth > 0)
                {
                    paint.fillRect(m_crossTipColor, size.cx - m_rightVScaleWidth, drawY - tSize2.cy / 2 - 4,
                        size.cx - m_rightVScaleWidth + tSize2.cx, drawY + tSize2.cy / 2 + 3);
                    paint.drawText(rightText, getTextColor(), getFont(),
                        new FCRect(size.cx - m_rightVScaleWidth, drawY - tSize2.cy / 2, size.cx - m_rightVScaleWidth + tSize2.cx, drawY + tSize2.cy / 2), -1);
                }
                //绘制十字线
                int drawX = getChartX(m_crossStopIndex);
                if (m_targetOldX == 0 && m_targetOldX2 == 0)
                {
                    drawX = m_touchPosition.x;
                }
                if (drawX < m_leftVScaleWidth)
                {
                    drawX = m_leftVScaleWidth;
                }
                if (drawX > size.cx - m_rightVScaleWidth)
                {
                    drawX = size.cx - m_rightVScaleWidth;
                }
                if (m_showCrossLine)
                {
                    paint.drawLine(m_crossLineColor, m_lineWidthChart, 0,
                           m_leftVScaleWidth, drawY, size.cx - m_rightVScaleWidth, drawY);
                    paint.drawLine(m_crossLineColor, m_lineWidthChart, 0, drawX, 0,
                           drawX, getHeight() - m_hScaleHeight);
                }
                int cRealIndex = getChartIndexReal(getTouchPoint());
                if ((cRealIndex != -1 && cRealIndex > m_firstVisibleIndex) && (cRealIndex < m_datas.size() || cRealIndex - m_firstVisibleIndex < m_dates.size()))
                {
                    double dateNum = 0;
                    if (m_dates.size() > 0 && cRealIndex - m_firstVisibleIndex < m_dates.size())
                    {
                        dateNum = m_dates.get(cRealIndex - m_firstVisibleIndex);
                    }
                    else
                    {
                        dateNum = m_datas[cRealIndex].m_date;
                    }
                    String xText = dateNum.ToString();
                    DateTime dt = FCTran.numToDate(dateNum);
                    if (m_cycle == "day")
                    {
                        xText = dt.ToString("yyyy/MM/dd") + ",";
                        xText += getWeekStr(StockService.dayOfWeek(dt.Year, dt.Month, dt.Day));
                    }
                    else if (m_cycle == "minute")
                    {
                        xText = dt.ToString("yyyy/MM/dd HH:mm") + ",";
                        xText += getWeekStr(StockService.dayOfWeek(dt.Year, dt.Month, dt.Day));
                    }
                    else
                    {
                        if (m_hScaleFormat.Length > 0)
                        {
                            xText = dt.ToString(m_hScaleFormat);
                        }
                        else
                        {
                            xText = dt.ToString("HH:mm");
                        }
                    }
                    FCSize xSize = paint.textSize(xText, getFont(), -1);
                    int bTop = m_size.cy - m_hScaleHeight;
                    paint.fillRect(
                        m_crossTipColor,
                        drawX - xSize.cx / 2 - 2,
                        bTop,
                        drawX + xSize.cx / 2 + 2,
                        bTop + xSize.cy + 6);
                    paint.drawText(xText, getTextColor(), getFont(), new FCRect(drawX - xSize.cx / 2,
                        bTop + 3, drawX + xSize.cx / 2,
                        bTop + 3 + xSize.cy), -1);
                }
            }
        }

        public ADJUSTMENTFACTOR m_touchFactor = null;
        public int m_sIndex = -1;

        public override void drawChartScale(FCPaint paint, FCRect clipRect)
        {
            m_dates.clear();
            m_touchFactor = null;
            m_sIndex = -1;
            FCSize size = getSize();
            int candleDivHeight = getCandleDivHeight();
            int volDivHeight = getVolDivHeight();
            int indDivHeight = getIndDivHeight();
            if (m_leftVScaleWidth > 0)
            {
                paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            m_leftVScaleWidth, 0, m_leftVScaleWidth,
                            size.cy);
            }
            if (m_rightVScaleWidth > 0)
            {
                paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            size.cx - m_rightVScaleWidth, 0, size.cx - m_rightVScaleWidth,
                            size.cy);
            }
            if (m_hScaleHeight > 0)
            {
                paint.drawLine(m_scaleColor, m_lineWidthChart, 0, 0,
                        getHeight() - m_hScaleHeight, size.cx, getHeight() - m_hScaleHeight);
            }
            if (volDivHeight > 0)
            {
                paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                        0, candleDivHeight, size.cx, candleDivHeight);
            }
            if (indDivHeight > 0)
            {
                paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                        m_leftVScaleWidth, candleDivHeight + volDivHeight,
                        size.cx - m_rightVScaleWidth,
                        candleDivHeight + volDivHeight);
            }
            if (m_datas.size() > 0)
            {
                FCPoint topPoint = new FCPoint(0, 20);
                FCPoint bottomPoint = new FCPoint(0, candleDivHeight - 10);
                double candleMax = getChartValue(topPoint);
                double candleMin = getChartValue(bottomPoint);
                chartGridScale(candleMin, candleMax, (candleDivHeight - m_candlePaddingTop - m_candlePaddingBottom) / 2,
                    m_vScaleDistance, m_vScaleDistance / 2,
                    (candleDivHeight - m_candlePaddingTop - m_candlePaddingBottom) / m_vScaleDistance);
                if (m_gridStep > 0)
                {
                    ArrayList<double> drawValues = new ArrayList<double>();
                    bool isTrend = m_cycle == "trend";
                    double firstOpen = 0;
                    if (isTrend)
                    {
                        if (m_firstOpen != 0)
                        {
                            firstOpen = m_firstOpen;
                        }
                        else
                        {
                            firstOpen = m_datas[m_firstVisibleIndex].m_close;
                        }
                        if (firstOpen == 0)
                        {
                            firstOpen = candleMin;
                        }
                        double subValue = (candleMax - candleMin);
                        int count = (candleDivHeight -
                                m_candlePaddingTop -
                                m_candlePaddingBottom) /
                            m_vScaleDistance;
                        if (count > 0)
                        {
                            subValue /= count;
                        }
                        double start = firstOpen;
                        while (start < candleMax)
                        {
                            start += subValue;
                            if (start <= candleMax)
                            {
                                drawValues.add(start);
                            }
                        }
                        start = firstOpen;
                        while (start > candleMin)
                        {
                            start -= subValue;
                            if (start >= candleMin)
                            {
                                drawValues.add(start);
                            }
                        }
                    }
                    else
                    {
                        double start = 0;
                        if (candleMin >= 0)
                        {
                            while (start + m_gridStep < candleMin)
                            {
                                start += m_gridStep;
                            }
                        }
                        else
                        {
                            while (start - m_gridStep > candleMin)
                            {
                                start -= m_gridStep;
                            }
                        }

                        while (start <= candleMax)
                        {
                            if (start > candleMin)
                            {
                                drawValues.add(start);
                            }
                            start += m_gridStep;
                        }
                    }
                    drawValues.add(firstOpen);
                    for (int i = 0; i < drawValues.size(); i++)
                    {
                        double start = drawValues[i];
                        int hAxisY = getChartY(0, start);
                        if (hAxisY < 1 || hAxisY >= candleDivHeight)
                        {
                            continue;
                        }
                        if (m_cycle == "trend" && start == firstOpen)
                        {
                            paint.drawLine(m_scaleColor, 1, 0,
                                   m_leftVScaleWidth, hAxisY,
                                   size.cx - m_rightVScaleWidth, hAxisY);
                        }
                        else
                        {
                            paint.drawLine(m_gridColor, m_lineWidthChart, 0,
                                m_leftVScaleWidth, hAxisY,
                                size.cx - m_rightVScaleWidth, hAxisY);
                        }
                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            size.cx - m_rightVScaleWidth, hAxisY,
                           size.cx - m_rightVScaleWidth + 8, hAxisY);

                        String drawText = FCTran.getValueByDigit(start, m_candleDigit);

                        FCSize tSize = paint.textSize(drawText, getFont(), -1);
                        if (isTrend)
                        {
                            double diffRange = ((start - firstOpen) / firstOpen * 100);
                            String diffRangeStr = FCTran.getValueByDigit(diffRange, 2) + "%".ToString();
                            FCSize dSize = paint.textSize(diffRangeStr, getFont(), -1);
                            if (diffRange > 0)
                            {
                                paint.drawText(diffRangeStr, FCColor.rgb(255, 82, 82), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), FCColor.rgb(255, 82, 82), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                            }
                            else if (diffRange < 0)
                            {
                                paint.drawText(diffRangeStr, FCColor.rgb(46, 255, 50), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), FCColor.rgb(46, 255, 50), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                            }
                            else
                            {
                                paint.drawText(diffRangeStr, m_textColor, getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), m_textColor, false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                            }
                        }
                        else
                        {
                            int digit = m_candleDigit;
                            if (m_candleMax > 1000)
                            {
                                digit = 0;
                            }
                            if (MyColor.m_style == 0)
                            {
                                FCDraw.drawUnderLineNum(paint, start, digit, getFont(), FCColor.rgb(233, 153, 46), false, size.cx - m_rightVScaleWidth + 12,
                                    hAxisY - tSize.cy / 2 - 1);
                            }
                            else
                            {
                                FCDraw.drawUnderLineNum(paint, start, digit, getFont(), getTextColor(), false, size.cx - m_rightVScaleWidth + 12,
                                    hAxisY - tSize.cy / 2 - 1);
                            }
                            if (MyColor.m_style == 0)
                            {
                                FCDraw.drawUnderLineNum(paint, start, digit, getFont(), FCColor.rgb(233, 153, 46), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                            }
                            else
                            {
                                FCDraw.drawUnderLineNum(paint, start, digit, getFont(), getTextColor(), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                            }
                        }
                    }
                }
                topPoint = new FCPoint(0, candleDivHeight + 10);
                bottomPoint = new FCPoint(0, candleDivHeight + volDivHeight - 10);
                double volMax = getChartValue(topPoint);
                double volMin = getChartValue(bottomPoint);
                chartGridScale(volMin, volMax, (volDivHeight - m_volPaddingTop - m_volPaddingBottom) / 2,
                    m_vScaleDistance, m_vScaleDistance / 2,
                    (volDivHeight - m_volPaddingTop - m_volPaddingBottom) / m_vScaleDistance);
                if (m_gridStep > 0)
                {
                    double start = 0;
                    if (volMin >= 0)
                    {
                        while (start + m_gridStep < volMin)
                        {
                            start += m_gridStep;
                        }
                    }
                    else
                    {
                        while (start - m_gridStep > volMin)
                        {
                            start -= m_gridStep;
                        }
                    }
                    while (start <= volMax)
                    {
                        if (start > volMin)
                        {
                            int hAxisY = getChartY(1, start);
                            if (hAxisY < candleDivHeight ||
                                   hAxisY > candleDivHeight + volDivHeight)
                            {
                                start += m_gridStep;
                                continue;
                            }
                            paint.drawLine(m_gridColor, m_lineWidthChart, 0, m_leftVScaleWidth,
                                hAxisY, size.cx - m_rightVScaleWidth, hAxisY);
                            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                                m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                            paint.drawLine(m_scaleColor, m_lineWidthChart, 0, size.cx - m_rightVScaleWidth,
                                hAxisY, size.cx - m_rightVScaleWidth + 8, hAxisY);
                            String drawText =
                                FCTran.getValueByDigit(start / m_magnitude, m_volDigit);
                            FCSize tSize = paint.textSize(drawText, getFont(), -1);
                            if (MyColor.m_style == 0)
                            {
                                paint.drawText(drawText, FCColor.rgb(233, 153, 46), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                paint.drawText(drawText, FCColor.rgb(233, 153, 46), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                            }
                            else
                            {
                                paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                            }
                        }
                        start += m_gridStep;
                    }
                }
                if (indDivHeight > 0)
                {
                    topPoint = new FCPoint(0, candleDivHeight + volDivHeight + 10);
                    bottomPoint =
                        new FCPoint(0, candleDivHeight + volDivHeight + indDivHeight - 10);
                    double indMax = getChartValue(topPoint);
                    double indMin = getChartValue(bottomPoint);
                    chartGridScale(indMin, indMax, (indDivHeight - m_indPaddingTop - m_indPaddingBottom) / 2,
                        m_vScaleDistance, m_vScaleDistance / 2,
                        (indDivHeight - m_indPaddingTop - m_indPaddingBottom) / m_vScaleDistance);
                    if (m_gridStep > 0)
                    {
                        double start = 0;
                        if (indMin >= 0)
                        {
                            while (start + m_gridStep < indMin)
                            {
                                start += m_gridStep;
                            }
                        }
                        else
                        {
                            while (start - m_gridStep > indMin)
                            {
                                start -= m_gridStep;
                            }
                        }

                        while (start <= indMax)
                        {
                            if (start > indMin)
                            {
                                int hAxisY = getChartY(2, start);
                                if (hAxisY < candleDivHeight + volDivHeight ||
                                    hAxisY > candleDivHeight + volDivHeight + indDivHeight)
                                {
                                    start += m_gridStep;
                                    continue;
                                }
                                paint.drawLine(m_gridColor, m_lineWidthChart, 0, m_leftVScaleWidth, hAxisY, size.cx - m_rightVScaleWidth, hAxisY);
                                paint.drawLine(m_scaleColor, m_lineWidthChart, 0, m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                                paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                                    size.cx - m_rightVScaleWidth, hAxisY, size.cx - m_rightVScaleWidth + 8, hAxisY);
                                String drawText = FCTran.getValueByDigit(start, m_indDigit);
                                FCSize tSize = paint.textSize(drawText, getFont(), -1);
                                paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                    hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                    hAxisY + tSize.cy / 2), -1);
                                paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                            }
                            start += m_gridStep;
                        }
                    }
                }
            }
            if (m_datas.size() > 0 && m_hScaleHeight > 0)
            {
                long newScaleColor = getTextColor();
                if (MyColor.m_style == 0)
                {
                    newScaleColor = FCColor.rgb(233, 153, 46);
                }
                if (m_cycle == "trend")
                {
                    ArrayList<double> times = new ArrayList<double>();
                    if (getWidth() < 600)
                    {
                        times.add(FCTran.getDateNum(1970, 1, 1, 10, 30, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 11, 30, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 14, 0, 0, 0));
                    }
                    else
                    {
                        times.add(FCTran.getDateNum(1970, 1, 1, 10, 0, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 10, 30, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 11, 0, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 11, 30, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 13, 30, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 14, 0, 0, 0));
                        times.add(FCTran.getDateNum(1970, 1, 1, 14, 30, 0, 0));
                    }
                    int bBottom = getHeight();
                    String leftStr = "9:30";
                    FCSize leftSize = paint.textSize(leftStr, getFont(), -1);
                    String rightStr = "15:00";
                    FCSize rightSize = paint.textSize(rightStr, getFont(), -1);
                    paint.drawText(leftStr, newScaleColor, getFont(), new FCRect(m_leftVScaleWidth + 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2, m_leftVScaleWidth + leftSize.cx + 5, bBottom - (m_hScaleHeight - leftSize.cy) / 2), -1);
                    paint.drawText(rightStr, newScaleColor, getFont(), new FCRect(size.cx - m_rightVScaleWidth - rightSize.cx - 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2, size.cx - m_rightVScaleWidth - 5, bBottom - (m_hScaleHeight - leftSize.cy) / 2), -1);
                    for (int i = m_firstVisibleIndex; i <= m_lastVisibleIndex; i++)
                    {
                        double dateNum = m_datas[i].m_date;
                        DateTime dt = FCTran.numToDate(dateNum);
                        double timeNum = FCTran.getDateNum(1970, 1, 1, dt.Hour, dt.Minute, 0, 0);
                        if (times.Contains(timeNum))
                        {
                            String xText = dt.ToString("HH:mm");
                            FCSize tSize = paint.textSize(xText, getFont(), -1);
                            int x = getChartX(i);
                            int dx = x - tSize.cx / 2;
                            paint.drawLine(m_scaleColor, m_lineWidthChart, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 5);
                            paint.drawText(xText, newScaleColor, getFont(), new FCRect(dx, bBottom - (m_hScaleHeight + leftSize.cy) / 2, dx + tSize.cx, bBottom - (m_hScaleHeight - leftSize.cy) / 2), -1);
                            paint.drawLine(m_gridColor, 1, 0, x, 0, x, bBottom - m_hScaleHeight);
                        }
                    }
                }
                else
                {
                    double dLeft = m_leftVScaleWidth;
                    if (m_cycle == "day")
                    {
                        if (StockService.m_factors.containsKey(m_myChart.m_code))
                        {
                            ArrayList<ADJUSTMENTFACTOR> factor = StockService.m_factors.get(m_myChart.m_code);
                            int startIndex = m_firstVisibleIndex;
                            String txtSignal = "S";
                            FCFont sFont = new FCFont("Default", 10.5f, false, false, false);
                            FCSize sSize = paint.textSize(txtSignal, sFont, -1);
                            FCPoint mp = getTouchPoint();
                            for (int i = 0; i < factor.size(); i++)
                            {
                                double date = factor.get(i).dwDate;
                                int drawIndex = -1;
                                for (int j = startIndex; j <= m_lastVisibleIndex; j++)
                                {
                                    double lastDate = 0;
                                    double nextDate = 0;
                                    if (j > 0)
                                    {
                                        lastDate = m_datas[j - 1].m_date;
                                    }
                                    if (j < m_datas.size() - 1)
                                    {
                                        nextDate = m_datas[j + 1].m_date;
                                    }
                                    if (date == m_datas[j].m_date || (date > lastDate && date < nextDate))
                                    {
                                        drawIndex = j;
                                        startIndex = j + 1;
                                        break;
                                    }
                                }
                                if (drawIndex != -1)
                                {
                                    int x = getChartX(drawIndex);
                                    FCDraw.drawText(paint, txtSignal, FCColor.rgb(255, 0, 0), sFont, x - sSize.cx / 2, candleDivHeight - sSize.cy);
                                    if (mp.x >= x - sSize.cx / 2 && mp.x <= x + sSize.cx / 2 && mp.y >= candleDivHeight - sSize.cy && mp.y <= candleDivHeight)
                                    {
                                        m_touchFactor = factor.get(i);
                                        m_sIndex = drawIndex;
                                    }
                                }
                            }
                        }
                    }
                    if (m_cycle == "day")
                    {
                        int fIndex = m_firstVisibleIndex;
                        int lIndex = m_lastVisibleIndex;
                        if (lIndex >= fIndex)
                        {
                            ArrayList<double> dates = new ArrayList<double>();
                            for (int d = fIndex; d <= lIndex; d++)
                            {
                                dates.add(m_datas.get(d).m_date);
                            }
                            int drawLeft = m_leftVScaleWidth; //左侧起画点
                            int i = fIndex; //开始索引
                            int lastYear = 0; //缓存年份，用于判断是否换年
                            ArrayList<int> drawYearsCache = new ArrayList<int>(); //实际绘制到图形上的年份文字
                            int lastTextRight = 0; //上个文字的右侧
                            ArrayList<DateTime> timeCache = new ArrayList<DateTime>(); //保存日期的缓存
                            ArrayList<int> yearTextLeftCache = new ArrayList<int>(); //绘制年文字的左侧位置缓存
                            ArrayList<int> yearTextRightCache = new ArrayList<int>(); //绘制年文字的右侧位置缓存
                            int textPadding = 5; //两个文字之间的最小间隔
                            //逐步递增索引，先绘制年
                            int bBottom = getHeight();
                            while (i <= lIndex)
                            {
                                DateTime dateObj = FCTran.numToDate(dates[i - fIndex]);
                                timeCache.add(dateObj);
                                int year = dateObj.Year; //从结构中获取年份			
                                int x = getChartX(i); //获取索引对应的位置
                                //判断是否换年，以及是否在绘图区间内
                                if (year != lastYear && x >= drawLeft && x < size.cx - m_rightVScaleWidth)
                                {
                                    int month = dateObj.Month; //获取月的结构
                                    String xText = year.ToString(); //拼接要绘制的文字
                                    FCSize tSize = paint.textSize(xText, getFont(), -1); //计算要绘制文字的大小
                                    //判断是否和上个文字重影
                                    int tLeft = x + 2;
                                    if (tLeft > lastTextRight)
                                    {
                                        paint.drawLine(m_scaleColor, 1, 0, x, bBottom - m_hScaleHeight, x, bBottom); //绘制刻度线
                                        FCDraw.drawText(paint, xText, newScaleColor, getFont(), tLeft, bBottom - (m_hScaleHeight + tSize.cy) / 2); //绘制文字
                                        yearTextLeftCache.add(tLeft); //将年文字的左侧位置缓存
                                        yearTextRightCache.add(tLeft + tSize.cx + 5); //将年文字的右侧位置缓存
                                        drawYearsCache.add(year); //缓存要绘制的年
                                        lastTextRight = tLeft + tSize.cx + 5; //缓存上个文字的右侧位置
                                        lastYear = year; //记录上次绘制的年份
                                    }
                                }
                                i = i + 1;	//索引累加
                            }
                            if (m_myChart.m_cycle <= 1440)
                            {
                                //绘制月份
                                for (int m = 0; m < drawYearsCache.size(); m++)
                                {
                                    int cacheYear = drawYearsCache[m]; //从缓存中获取年份
                                    int lastMonth = 0; //缓存月份，用于判断是否换月
                                    i = m_firstVisibleIndex; //重置开始索引
                                    lastTextRight = 0; //重置上个文字的右侧
                                    //逐步递增索引
                                    while (i <= lIndex)
                                    {
                                        DateTime dateObj = timeCache[i - m_firstVisibleIndex]; //从缓存中获取time
                                        int year = dateObj.Year; //从结构中获取年份
                                        //判断是否同一年	
                                        if (cacheYear == year)
                                        {
                                            int month = dateObj.Month; //从结构中获取月份
                                            int x = getChartX(i);
                                            //判断是否换月，以及是否在绘图区间内
                                            if (lastMonth != month && x >= drawLeft && x < size.cx - m_rightVScaleWidth)
                                            {
                                                String xText = month.ToString(); //获取绘制的月份文字
                                                if (xText.Length == 1)
                                                {
                                                    xText = "0" + xText;
                                                }
                                                FCSize tSize = paint.textSize(xText, getFont(), -1); //计算要绘制文字的大小
                                                //判断是否和上个文字重影
                                                if (x > lastTextRight + textPadding)
                                                {
                                                    if ((x > yearTextRightCache[m] + textPadding)
                                                    && ((m == drawYearsCache.size() - 1)
                                                    || ((m < drawYearsCache.size() - 1)
                                                    && (x + tSize.cx < yearTextLeftCache[m + 1] - textPadding))))
                                                    {
                                                        paint.drawLine(m_scaleColor, 1, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 12); //绘制刻度
                                                        FCDraw.drawText(paint, xText, newScaleColor, getFont(), x + 2, bBottom - (m_hScaleHeight + tSize.cy) / 2); //绘制文字
                                                        lastTextRight = x + tSize.cx + 2; //缓存上个文字的右侧位置
                                                    }
                                                }
                                                lastMonth = month; //记录上次绘制的月份
                                            }
                                        }
                                        else if (cacheYear < year)
                                        {
                                            break; //超过区间，退出循环
                                        }
                                        i = i + 1;	//索引累加
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        int fIndex = m_firstVisibleIndex;
                        int lIndex = m_lastVisibleIndex;
                        if (lIndex >= fIndex)
                        {
                            DateTime lastDate2 = DateTime.MinValue;
                            ArrayList<double> dates = new ArrayList<double>();
                            for (int d = fIndex; d <= lIndex; d++)
                            {
                                dates.add(m_datas.get(d).m_date);
                            }
                            for (int i = fIndex; i <= lIndex; i++)
                            {
                                double dateNum = dates[i - fIndex];
                                String xText = dateNum.ToString();
                                DateTime dt = FCTran.numToDate(dateNum);
                                DateTime dText = new DateTime(dt.Year, dt.Month, dt.Day);
                                if (dText.Year != lastDate2.Year)
                                {
                                    xText = dt.ToString("yyyy/MM/dd");
                                }
                                else
                                {
                                    xText = dt.ToString("MM/dd");
                                }
                                if (dText != lastDate2)
                                {
                                    lastDate2 = dText;
                                    FCSize tSize = paint.textSize(xText, getFont(), -1);
                                    int x = getChartX(i);
                                    int dx = x + 2;
                                    if (dx > dLeft && dx + tSize.cx < size.cx - m_rightVScaleWidth - 5)
                                    {
                                        int bBottom = getHeight();
                                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 12);
                                        paint.drawText(xText, newScaleColor, getFont(), new FCRect(dx, bBottom - (m_hScaleHeight + tSize.cy) / 2, dx + tSize.cx, bBottom - (m_hScaleHeight + tSize.cy) / 2), -1);
                                        i = i + (int)((tSize.cx + m_hScaleTextDistance) / m_hScalePixel) + 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 根据位置计算索引
        /// </summary>
        /// <param name="mp">坐标</param>
        /// <returns></returns>
        public int getChartIndexReal(FCPoint mp)
        {
            if (m_datas.size() == 0)
            {
                return -1;
            }
            if (mp.x <= 0)
            {
                return 0;
            }
            double intX = mp.x - m_leftVScaleWidth - m_hScalePixel - m_offsetX;
            if (intX < 0)
            {
                intX = 0;
            }
            int index = (int)(m_firstVisibleIndex + intX / m_hScalePixel);
            int intPixel = (int)m_hScalePixel;
            if (intPixel > 0 && intX % intPixel != 0)
            {
                index++;
            }
            return index;
        }

        /// <summary>
        /// 绘图方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public override void onPaint(FCPaint paint, FCRect clipRect)
        {
            base.onPaint(paint, clipRect);
            int cycle = m_myChart.m_cycle;
            String sName = "";
            if (cycle == 0)
            {
                sName = "实时";
            }
            else if (cycle < 1440)
            {
                sName = FCTran.intToStr(cycle) + "分";
            }
            else if (cycle == 1440)
            {
                sName = "日线";
            }
            else if (cycle == 10080)
            {
                sName = "周线";
            }
            else if (cycle == 43200)
            {
                sName = "月线";
            }
            else if (cycle == 129600)
            {
                sName = "季线";
            }
            else if (cycle == 259200)
            {
                sName = "半年线";
            }
            else if (cycle == 518400)
            {
                sName = "年线";
            }
            if (sName.Length > 0)
            {
                FCFont font = getFont();
                FCSize tSize = paint.textSize(sName, font, -1);
                int width = getWidth(), height = getHeight();
                int tX = width - m_rightVScaleWidth / 2 - tSize.cx / 2;
                int tY = getHeight() - m_hScaleHeight / 2 - tSize.cy / 2;
                if (MyColor.m_style == 0)
                {
                    FCDraw.drawText(paint, sName, FCColor.rgb(249, 237, 6), font, tX, tY);
                }
                else
                {
                    FCDraw.drawText(paint, sName, FCColor.Text, font, tX, tY);
                }
            }
            if (m_touchFactor != null)
            {
                int x = getChartX(m_sIndex);
                int candleDivHeight = getCandleDivHeight();
                ArrayList<String> strs = new ArrayList<string>();
                strs.add("权息变动");
                strs.add("除权除息:" + FCTran.numToDate(m_touchFactor.dwDate).ToString("yyyy/MM/dd"));
                if (m_touchFactor.f1 > 0)
                {
                    strs.add("每10股派现金" + FCTran.floatToStr(m_touchFactor.f1) + "元");
                }
                if (m_touchFactor.f3 > 0)
                {
                    strs.add("每10股送股" + FCTran.floatToStr(m_touchFactor.f1) + "股");
                }
                if (m_touchFactor.f4 > 0)
                {
                    strs.add("每10股配股" + FCTran.floatToStr(m_touchFactor.f1) + "元");
                }
                FCRect sRect = new FCRect(x, candleDivHeight, x + 150, candleDivHeight + strs.size() * 20);
                if (sRect.bottom > getHeight())
                {
                    int sHeight = sRect.bottom - sRect.top;
                    sRect.top = candleDivHeight - sHeight - 20;
                    sRect.bottom = sRect.top + sHeight;
                }
                paint.fillRect(FCColor.Back, sRect);
                paint.drawRect(FCColor.Border, 1, 0, sRect);
                for (int i = 0; i < strs.size(); i++)
                {
                    String str = strs[i];
                    FCDraw.drawText(paint, str, getTextColor(), getFont(), sRect.left + 3, sRect.top + 2 + i * 20);
                }
            }
            if (m_floatStrs.size() > 0 && m_tick == 0)
            {
                int rowHeight = 18;
                FCFont font = new FCFont("Default", 13, false, false, false);
                FCPoint mp = getTouchPoint();
                int tWidth = 0;
                for (int i = 0; i < m_floatStrs.size(); i++)
                {
                    String str = m_floatStrs.get(i);
                    FCSize tSize = paint.textSize(str, font, -1);
                    if (tWidth < tSize.cx)
                    {
                        tWidth = tSize.cx;
                    }
                }
                FCRect sRect = new FCRect(mp.x + 15, mp.y, mp.x + tWidth + 30, mp.y + m_floatStrs.size() * rowHeight + 10);
                int sWidth = sRect.right - sRect.left;
                int sHeight = sRect.bottom - sRect.top;
                if (sRect.bottom > getSize().cy)
                {
                    sRect.top = 20;
                    sRect.bottom = sRect.top + sHeight;
                }
                else if (sRect.top < 0)
                {
                    sRect.top = 0;
                    sRect.bottom = sHeight;
                }
                if (sRect.right > getWidth())
                {
                    sRect.left = getWidth() - sWidth;
                    sRect.right = sRect.left + sWidth;
                }
                if (MyColor.m_style == 0)
                {
                    m_native.getPaint().fillRect(FCColor.rgba(0, 0, 0, 150), sRect);
                }
                else
                {
                    m_native.getPaint().fillRect(FCColor.rgba(255, 255, 255, 150), sRect);
                }
                m_native.getPaint().drawRect(MyColor.USERCOLOR104, 1, 0, sRect);
                for (int i = 0; i < m_floatStrs.size(); i++)
                {
                    String str = m_floatStrs.get(i);
                    FCDraw.drawText(m_native.getPaint(), str, FCColor.Text, font, sRect.left + 5, sRect.top + rowHeight * i + 3);
                }
            }
        }

        public FCMenu m_menu = null;

        /// <summary>
        /// 触摸按下方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public override void onTouchDown(FCTouchInfo touchInfo)
        {
            callTouchEvents(FCEventID.TouchDown, touchInfo);
            if (touchInfo.m_firstTouch)
            {
                FCPoint mp = touchInfo.m_firstPoint;
                m_resizeDiv = false;
                if (m_volDivPercent > 0)
                {
                    int candleDivHeight = getCandleDivHeight();
                    int hScalePos = candleDivHeight;
                    if (mp.y >= hScalePos - 3 && mp.y <= hScalePos + 3)
                    {
                        m_resizeDiv = true;
                    }
                }
                if (!m_resizeDiv)
                {
                    touchDownChart(touchInfo.m_firstTouch, touchInfo.m_firstPoint, touchInfo.m_secondTouch, touchInfo.m_secondPoint, touchInfo.m_clicks);
                }
            }
            invalidate();
        }

        public int m_timerID;

        public int m_tick;

        public override void onTimer(int timerID)
        {
            base.onTimer(timerID);
            if (m_tick > 0)
            {
                m_tick--;
                if (m_tick == 0)
                {
                    stopTimer(m_timerID);
                    invalidate();
                }
            }
        }

        /// <summary>
        /// 触摸移动方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public override void onTouchMove(FCTouchInfo touchInfo)
        {
            callTouchEvents(FCEventID.TouchMove, touchInfo);
            m_floatStrs.clear();
            stopTimer(m_timerID);
            m_tick = 0;
            FCPoint mp = touchInfo.m_firstPoint;
            if (m_volDivPercent > 0)
            {
                int candleDivHeight = getCandleDivHeight();
                int hScalePos = candleDivHeight;
                if (m_resizeDiv || (mp.y >= hScalePos - 3 && mp.y <= hScalePos + 3))
                {
                    setCursor(FCCursors.SizeNS);
                }
                else
                {
                    setCursor(FCCursors.Arrow);
                }
            }
            if (m_resizeDiv)
            {
                int contentHeight = (getHeight() - m_hScaleHeight);
                if (contentHeight > 0)
                {
                    double rate = (double)mp.y / contentHeight;
                    if (rate >= 0.1 && rate <= 0.9)
                    {
                        m_candleDivPercent = rate;
                        m_volDivPercent = 1 - rate;
                        invalidate();
                    }
                }
            }
            else
            {
                touchMoveChart(touchInfo.m_firstTouch, touchInfo.m_firstPoint, touchInfo.m_secondTouch, touchInfo.m_secondPoint);
                if (m_datas.size() > 0 && m_cycle != "trend")
                {
                    int crossStopIndex = getChartIndexReal(touchInfo.m_firstPoint);
                    if (crossStopIndex >= 0 && crossStopIndex <= m_lastVisibleIndex && crossStopIndex < m_datas.size())
                    {
                        SecurityData securityData = m_datas[crossStopIndex];
                        int highY = getChartY(0, securityData.m_high);
                        int lowY = getChartY(0, securityData.m_low);
                        if (mp.y >= Math.Min(highY, lowY) - 5 && mp.y <= Math.Max(highY, lowY) + 5)
                        {
                            double lastClose = securityData.m_close;
                            if (crossStopIndex > 0)
                            {
                                lastClose = m_datas[crossStopIndex - 1].m_close;
                            }
                            FCFont tFont = new FCFont("Default", 12f);
                            Security security = new Security();
                            ArrayList<String> strs = new ArrayList<String>();
                            if (securityData.m_startDate > 0 && securityData.m_endDate > 0)
                            {
                                DateTime startDate = FCTran.numToDate(securityData.m_startDate);
                                DateTime endDate = FCTran.numToDate(securityData.m_endDate);
                                int dayOfWeek1 = StockService.dayOfWeek(startDate.Year, startDate.Month, startDate.Day);
                                int dayOfWeek2 = StockService.dayOfWeek(endDate.Year, endDate.Month, endDate.Day);
                                String strWeek1 = getWeekStr(dayOfWeek1);
                                String strWeek2 = getWeekStr(dayOfWeek2);
                                String strDate1 = startDate.ToString(m_hScaleFormat);
                                if (m_myChart.m_cycle >= 1440)
                                {
                                    strDate1 = startDate.ToString("yyyy/MM/dd");
                                }
                                else
                                {
                                    strDate1 = startDate.ToString("yyyy/MM/dd HH:mm");
                                }
                                String strDate2 = endDate.ToString(m_hScaleFormat);
                                if (m_myChart.m_cycle >= 1440)
                                {
                                    strDate2 = endDate.ToString("yyyy/MM/dd");
                                }
                                else
                                {
                                    strDate2 = endDate.ToString("yyyy/MM/dd HH:mm");
                                }
                                if (m_myChart.m_cycle >= 1440)
                                {
                                    strs.add("起:" + strDate1 + "," + strWeek1);
                                    strs.add("止:" + strDate2 + "," + strWeek2);
                                }
                                else
                                {
                                    strs.add("起:" + strDate1);
                                    strs.add("止:" + strDate2);
                                }
                            }
                            else
                            {
                                DateTime dateTime = FCTran.numToDate(securityData.m_date);
                                int dayOfWeek = StockService.dayOfWeek(dateTime.Year, dateTime.Month, dateTime.Day);
                                String strDate = dateTime.ToString(m_hScaleFormat);
                                if (m_myChart.m_cycle >= 1440)
                                {
                                    strDate = dateTime.ToString("yyyy/MM/dd");
                                }
                                else
                                {
                                    strDate = dateTime.ToString("yyyy/MM/dd HH:mm");
                                }
                                String strWeek = getWeekStr(dayOfWeek);
                                if (m_myChart.m_cycle >= 1440)
                                {
                                    strs.add(strDate + "," + strWeek);
                                }
                                else
                                {
                                    strs.add(strDate);
                                }
                            }
                            strs.add("开:" + FCTran.getValueByDigit(securityData.m_open, 2));
                            strs.add("高:" + FCTran.getValueByDigit(securityData.m_high, 2));
                            strs.add("低:" + FCTran.getValueByDigit(securityData.m_low, 2));
                            strs.add("收:" + FCTran.getValueByDigit(securityData.m_close, 2));
                            strs.add("量:" + FCTran.getValueByDigit(securityData.m_volume / 100, 0) + "手");
                            strs.add("额:" + FCTran.getValueByDigit(securityData.m_amount / 10000, 0) + "万");
                            double rate = 0;
                            if (lastClose != 0)
                            {
                                rate = 100 * (securityData.m_close - lastClose) / lastClose;
                            }
                            strs.add("涨:" + FCTran.getValueByDigit(rate, 2) + "%");
                            double range = 0;
                            if (lastClose != 0)
                            {
                                range = 100 * (securityData.m_high - lastClose) / lastClose - 100 * (securityData.m_low - lastClose) / lastClose;
                            }
                            strs.add("振:" + FCTran.getValueByDigit(range, 2) + "%");
                            m_floatStrs = strs;
                            m_tick = 3;
                            startTimer(m_timerID, 100);
                        }
                    }
                }
            }
            invalidate();
        }

        /// <summary>
        /// 触摸抬起方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public override void onTouchUp(FCTouchInfo touchInfo)
        {
            if (m_resizeDiv)
            {
                m_resizeDiv = false;
            }
            else
            {
                if (touchInfo.m_secondTouch)
                {
                    if (m_menu == null)
                    {
                        m_menu = new FCMenu();
                        m_menu.setPopup(true);
                        m_menu.setWidth(100);
                        m_menu.setMinimumSize(new FCSize(100, 50));
                        m_menu.addEvent(this, "onmenuitemclick", this);
                        m_native.addView(m_menu);
                        ArrayList<String> titles = new ArrayList<String>();
                        titles.add("进入全屏");
                        titles.add("显示成交量");
                        for (int i = 0; i < titles.size(); i++)
                        {
                            FCMenuItem menuItem1 = new FCMenuItem(titles[i]);
                            m_menu.addItem(menuItem1);
                        }
                    }
                    if (m_oldParent != null)
                    {
                        m_menu.m_items.get(0).setText("退出全屏");
                    }
                    else
                    {
                        m_menu.m_items.get(0).setText("进入全屏");
                    }
                    if (m_volDivPercent == 0)
                    {
                        m_menu.m_items.get(1).setText("显示成交量");
                    }
                    else
                    {
                        m_menu.m_items.get(1).setText("隐藏成交量");
                    }
                    m_menu.setLocation(m_native.getTouchPoint());
                    m_menu.show();
                }
                callTouchEvents(FCEventID.TouchUp, touchInfo);
                m_firstTouchIndexCache = -1;
                invalidate();
            }
        }

        public bool m_resizeDiv = false;

        public MyChart m_myChart = null;

        public FCComboBox m_subComboBox = null;

        /// <summary>
        /// 添加视图
        /// </summary>
        public override void onAdd()
        {
            base.onAdd();
            if (m_subComboBox == null)
            {
                m_subComboBox = new FCComboBox();
                addView(m_subComboBox);
                m_subComboBox.setVisible(false);
                m_subComboBox.setReadOnly(true);
                m_subComboBox.setFont(new FCFont("Default", 12f));
                m_subComboBox.setLineHeight(10);
                m_subComboBox.setBorderColor(FCColor.None);
                m_subComboBox.setText("不复权");
                m_subComboBox.setTextColor(FCColor.Text);
                ArrayList<String> subStrs = new ArrayList<string>();
                subStrs.add("前复权");
                subStrs.add("后复权");
                subStrs.add("不复权");
                for (int i = 0; i < subStrs.size(); i++)
                {
                    FCMenuItem menuItem = new FCMenuItem();
                    menuItem.setText(subStrs.get(i));
                    menuItem.setBorderColor(FCColor.None);
                    m_subComboBox.addItem(menuItem);
                }
                m_subComboBox.update();
                m_subComboBox.setSelectedIndex(0);
                m_subComboBox.getDropDownButton().setBorderColor(FCColor.None);
                m_subComboBox.getDropDownMenu().setMinimumSize(new FCSize(80, 60));
                m_subComboBox.addEvent(this, "onselectedindexchanged", this);
            }
        }

        public int m_keyDownTick = 0;

        /// <summary>
        /// 键盘抬起事件
        /// </summary>
        /// <param name="key"></param>
        public override void onKeyUp(char key)
        {
            base.onKeyUp(key);
            m_keyDownTick = 0;
        }

        /// <summary>
        /// 获取复权状态
        /// </summary>
        /// <returns></returns>
        public int getSubScription()
        {
            int sIndex = m_subComboBox.getSelectedIndex();
            if (sIndex == 0)
            {
                return 1;
            }
            else if (sIndex == 1)
            {
                return 2;
            }
            else
            {
                return 0;
            }
        }

        /// <summary>
        /// 调用事件
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="sender"></param>
        /// <param name="invoke"></param>
        public void callEvent(string eventName, object sender, object invoke)
        {
            if (m_myChart.m_cycle > 0)
            {
                m_myChart.m_lastPixel = m_hScalePixel;
            }
            m_myChart.searchSecurity(m_myChart.m_code, m_myChart.m_cycle);
        }

        /// <summary>
        /// 获取星期字符串
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        public static String getWeekStr(int week)
        {
            switch (week)
            {
                case 0:
                    return "一";
                case 1:
                    return "二";
                case 2:
                    return "三";
                case 3:
                    return "四";
                case 4:
                    return "五";
                case 5:
                    return "六";
                default:
                    return "日";
            }
        }

        public FCSplitLayoutDiv m_oldParent = null;

        public int m_isFirstOrSecond;

        /// <summary>
        /// 全屏
        /// </summary>
        public void fullScreen()
        {
            FCView divInner = m_native.findView("divInner");
            if (this.getParent().getParent().getParent() != divInner)
            {
                m_oldParent = this.getParent().getParent().getParent() as FCSplitLayoutDiv;
                FCView thisView = this.getParent().getParent();
                thisView.setDock(FCDockStyle.Fill);
                thisView.setBackColor(FCColor.Back);
                m_oldParent.removeView(thisView);
                if (m_oldParent.getFirstView() == thisView)
                {
                    m_isFirstOrSecond = 0;
                    m_oldParent.setFirstView(null);
                }
                else if (m_oldParent.getSecondView() == thisView)
                {
                    m_isFirstOrSecond = 1;
                    m_oldParent.setSecondView(null);
                }
                m_native.findView("tabFunc").setVisible(false);
                divInner.addView(thisView);
                this.focus();
            }
            else
            {
                m_native.findView("tabFunc").setVisible(true);
                FCView thisView = this.getParent().getParent();
                divInner.removeView(thisView);
                m_oldParent.addView(thisView);
                if (m_isFirstOrSecond == 0)
                {
                    m_oldParent.setFirstView(thisView);
                }
                else
                {
                    m_oldParent.setSecondView(thisView);
                }
                this.focus();
                m_oldParent = null;
            }
            getNative().update();
            getNative().invalidate();
        }

        public void callMenuItemTouchEvent(string eventName, object sender, FCMenuItem item, FCTouchInfo touchInfo, object invoke)
        {
            if (item.getText() == "进入全屏" || item.getText() == "退出全屏")
            {
                fullScreen();
            }
            else if (item.getText() == "显示成交量")
            {
                m_candleDivPercent = 0.7;
                m_volDivPercent = 0.3;
                invalidate();
            }
            else if (item.getText() == "隐藏成交量")
            {
                m_candleDivPercent = 1;
                m_volDivPercent = 0;
                invalidate();
            }
        }
    }
}
